﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyVoteMVC.Domain;
using System.Data.Entity.ModelConfiguration;

namespace MyVoteMVC.Data.Mapping
{
    public class VT_TicketsMap : EntityTypeConfiguration<VT_Tickets>
    {
        public VT_TicketsMap()
        {
            // Primary Key
            this.HasKey(t => t.Ticket_ID);

            // Properties
            this.Property(t => t.Ticket_ID)
                .IsRequired()
                .HasMaxLength(36);

            this.Property(t => t.Activity_ID)
                .HasMaxLength(36);

            this.Property(t => t.User_ID)
                .HasMaxLength(36);

            this.Property(t => t.Created_By)
                .HasMaxLength(100);

            this.Property(t => t.Created_Action)
                .HasMaxLength(200);

            this.Property(t => t.Last_Update_By)
                .HasMaxLength(100);

            this.Property(t => t.Last_Update_Action)
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("VT_Tickets");
            this.Property(t => t.Ticket_ID).HasColumnName("Ticket_ID");
            this.Property(t => t.Activity_ID).HasColumnName("Activity_ID");
            this.Property(t => t.User_ID).HasColumnName("User_ID");
            this.Property(t => t.Ticket_No).HasColumnName("Ticket_No");
            this.Property(t => t.Ticket_Content).HasColumnName("Ticket_Content");
            this.Property(t => t.Ticket_Status).HasColumnName("Ticket_Status");
            this.Property(t => t.Ticket_SubmitTime).HasColumnName("Ticket_SubmitTime");
            this.Property(t => t.Created_By).HasColumnName("Created_By");
            this.Property(t => t.Created_Date).HasColumnName("Created_Date");
            this.Property(t => t.Created_Action).HasColumnName("Created_Action");
            this.Property(t => t.Last_Update_By).HasColumnName("Last_Update_By");
            this.Property(t => t.Last_Update_Date).HasColumnName("Last_Update_Date");
            this.Property(t => t.Last_Update_Action).HasColumnName("Last_Update_Action");

            // Relationships
            this.HasRequired(t => t.Activity)
                .WithMany(t => t.Tickets)
                .HasForeignKey(d => d.Activity_ID);

            this.HasRequired(t => t.User)
                .WithMany(t => t.Tickets)
                .HasForeignKey(d => d.User_ID);

        }
    }
}
